{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np \n",
    "from itertools import product"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "countries = ['us','de','dk','fr','it','nl','se','sp']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>value</th>\n",
       "      <th>free</th>\n",
       "      <th>se</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>sigma</th>\n",
       "      <td>2.096055</td>\n",
       "      <td>True</td>\n",
       "      <td>0.063596</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>beta</th>\n",
       "      <td>0.970000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>phi</th>\n",
       "      <td>0.294007</td>\n",
       "      <td>True</td>\n",
       "      <td>0.049669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>psi</th>\n",
       "      <td>0.142842</td>\n",
       "      <td>True</td>\n",
       "      <td>0.004335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>delta_h1</th>\n",
       "      <td>-0.988275</td>\n",
       "      <td>True</td>\n",
       "      <td>0.062279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>delta_h2</th>\n",
       "      <td>3.485250</td>\n",
       "      <td>True</td>\n",
       "      <td>0.013469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eta</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tfp</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>price</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>risk</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             value   free        se\n",
       "name                               \n",
       "sigma     2.096055   True  0.063596\n",
       "beta      0.970000  False       NaN\n",
       "phi       0.294007   True  0.049669\n",
       "psi       0.142842   True  0.004335\n",
       "delta_h1 -0.988275   True  0.062279\n",
       "delta_h2  3.485250   True  0.013469\n",
       "eta       0.000000  False       NaN\n",
       "tfp       1.000000  False       NaN\n",
       "price     1.000000  False       NaN\n",
       "risk      0.000000  False       NaN"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test = pd.read_pickle('output/params_wage_us.pkl')\n",
    "test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "pars_select = ['delta_h1','delta_h2','price','tfp']\n",
    "stat = ['par','se']\n",
    "tuples = list(product(*[pars_select,stat]))\n",
    "table = pd.DataFrame(index=pd.MultiIndex.from_tuples(tuples),columns=countries)\n",
    "for c in countries: \n",
    "\tdf = pd.read_pickle('output/params_wage_'+c+'.pkl')\n",
    "\tfor p in pars_select:\n",
    "\t\ttable.loc[(p,'par'),c] = df.loc[p,'value']\n",
    "\t\ttable.loc[(p,'se'),c] = df.loc[p,'se']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "pars_select = ['delta_h1','delta_h2','price','tfp']\n",
    "labels = ['$\\\\alpha_{10}$','$\\\\alpha_{11}$','$\\\\frac{p}{p_{US}}$','$\\\\frac{A}{A_{US}}$']\n",
    "maps_labels = dict(zip(pars_select,labels))\n",
    "table.index = pd.MultiIndex.from_tuples(list(product(*[labels,['','se']])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "for c in table.columns:\n",
    "\ttable[c] = table[c].astype('float64')\n",
    "\ttable[c] = table[c].round(3)\n",
    "\ttable[c] = table[c].astype('str')\n",
    "\ttable[c] = np.where(table[c]=='nan','-',table[c])\n",
    "\tfor s in table.index:\n",
    "\t\tif s[1]=='se':\n",
    "\t\t\tif table.loc[s,c]!='-':\n",
    "\t\t\t\tfmt = \"({se})\"\n",
    "\t\t\t\ttable.loc[s,c] = fmt.format(se=table.loc[s,c])\n",
    "table.index = pd.MultiIndex.from_tuples(list(product(*[labels,['','']])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>us</th>\n",
       "      <th>de</th>\n",
       "      <th>dk</th>\n",
       "      <th>fr</th>\n",
       "      <th>it</th>\n",
       "      <th>nl</th>\n",
       "      <th>se</th>\n",
       "      <th>sp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">$\\alpha_{10}$</th>\n",
       "      <th></th>\n",
       "      <td>-0.988</td>\n",
       "      <td>-1.286</td>\n",
       "      <td>-1.597</td>\n",
       "      <td>-1.253</td>\n",
       "      <td>-0.801</td>\n",
       "      <td>-1.371</td>\n",
       "      <td>-1.406</td>\n",
       "      <td>-0.016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <td>(0.062)</td>\n",
       "      <td>(0.142)</td>\n",
       "      <td>(0.095)</td>\n",
       "      <td>(0.03)</td>\n",
       "      <td>(0.007)</td>\n",
       "      <td>(0.044)</td>\n",
       "      <td>(0.23)</td>\n",
       "      <td>(0.115)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">$\\alpha_{11}$</th>\n",
       "      <th></th>\n",
       "      <td>3.485</td>\n",
       "      <td>4.148</td>\n",
       "      <td>4.276</td>\n",
       "      <td>3.94</td>\n",
       "      <td>3.905</td>\n",
       "      <td>4.097</td>\n",
       "      <td>4.414</td>\n",
       "      <td>3.433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <td>(0.013)</td>\n",
       "      <td>(0.08)</td>\n",
       "      <td>(0.016)</td>\n",
       "      <td>(0.032)</td>\n",
       "      <td>(0.07)</td>\n",
       "      <td>(0.055)</td>\n",
       "      <td>(0.028)</td>\n",
       "      <td>(0.12)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">$\\frac{p}{p_{US}}$</th>\n",
       "      <th></th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.85</td>\n",
       "      <td>0.794</td>\n",
       "      <td>0.583</td>\n",
       "      <td>0.605</td>\n",
       "      <td>0.618</td>\n",
       "      <td>0.889</td>\n",
       "      <td>0.561</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <td>-</td>\n",
       "      <td>(0.013)</td>\n",
       "      <td>(0.066)</td>\n",
       "      <td>(0.018)</td>\n",
       "      <td>(0.006)</td>\n",
       "      <td>(0.054)</td>\n",
       "      <td>(0.02)</td>\n",
       "      <td>(0.02)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">$\\frac{A}{A_{US}}$</th>\n",
       "      <th></th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.022</td>\n",
       "      <td>1.259</td>\n",
       "      <td>0.923</td>\n",
       "      <td>0.643</td>\n",
       "      <td>1.005</td>\n",
       "      <td>0.801</td>\n",
       "      <td>0.814</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <td>-</td>\n",
       "      <td>(0.217)</td>\n",
       "      <td>(0.01)</td>\n",
       "      <td>(0.018)</td>\n",
       "      <td>(0.039)</td>\n",
       "      <td>(0.004)</td>\n",
       "      <td>(0.012)</td>\n",
       "      <td>(0.011)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          us       de       dk       fr       it       nl  \\\n",
       "$\\alpha_{10}$         -0.988   -1.286   -1.597   -1.253   -0.801   -1.371   \n",
       "                     (0.062)  (0.142)  (0.095)   (0.03)  (0.007)  (0.044)   \n",
       "$\\alpha_{11}$          3.485    4.148    4.276     3.94    3.905    4.097   \n",
       "                     (0.013)   (0.08)  (0.016)  (0.032)   (0.07)  (0.055)   \n",
       "$\\frac{p}{p_{US}}$       1.0     0.85    0.794    0.583    0.605    0.618   \n",
       "                           -  (0.013)  (0.066)  (0.018)  (0.006)  (0.054)   \n",
       "$\\frac{A}{A_{US}}$       1.0    1.022    1.259    0.923    0.643    1.005   \n",
       "                           -  (0.217)   (0.01)  (0.018)  (0.039)  (0.004)   \n",
       "\n",
       "                          se       sp  \n",
       "$\\alpha_{10}$         -1.406   -0.016  \n",
       "                      (0.23)  (0.115)  \n",
       "$\\alpha_{11}$          4.414    3.433  \n",
       "                     (0.028)   (0.12)  \n",
       "$\\frac{p}{p_{US}}$     0.889    0.561  \n",
       "                      (0.02)   (0.02)  \n",
       "$\\frac{A}{A_{US}}$     0.801    0.814  \n",
       "                     (0.012)  (0.011)  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/5n/x381756n3690kb86tk48yks00000gp/T/ipykernel_36354/41189828.py:1: FutureWarning: In future versions `DataFrame.to_latex` is expected to utilise the base implementation of `Styler.to_latex` for formatting and rendering. The arguments signature may therefore change. It is recommended instead to use `DataFrame.style.to_latex` which also contains additional functionality.\n",
      "  table.to_latex('../tables/table_e2_country_specific_estimates.tex')\n"
     ]
    }
   ],
   "source": [
    "table.to_latex('../tables/table_e2_country_specific_estimates.tex')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Average US-EU differences\n",
    "\n",
    "This number is used in counterfactual analysis. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7000000000000001"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.index = pd.MultiIndex.from_tuples(list(product(*[labels,['p','se']])))\n",
    "prices = table.loc[('$\\\\frac{p}{p_{US}}$','p'),:]\n",
    "prices['de':].astype('float64').mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9238571428571428"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.index = pd.MultiIndex.from_tuples(list(product(*[labels,['p','se']])))\n",
    "prices = table.loc[('$\\\\frac{A}{A_{US}}$','p'),:]\n",
    "prices['de':].astype('float64').mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "cf2a50979671a58939829e6829efb726aa5da11149213b77bd50351f899d04fb"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
